<template>
  <div class="container">
    <div class="number">{{ battery.level }}%</div>
    <div class="contrast">
      <div class="circle"></div>
      <ul class="bubbles">
        <li v-for="i in 15" :key="i"></li>
      </ul>
    </div>
    <div class="charging">
      <div>{{ batteryStatus }}</div>
      <div
        v-show="
          Number.isFinite(battery.dischargingTime) &&
          battery.dischargingTime != 0
        "
      >
        剩余可使用时间：{{ calcDischargingTime }}
      </div>
      <span
        v-show="
          Number.isFinite(battery.chargingTime) && battery.chargingTime != 0
        "
      >
        距离电池充满需要：{{ calcChargingTime }}
      </span>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  name: "HuaweiCharge",
  props: {
    battery: {
      // 电池对象
      type: Object,
      default: () => ({}),
    },
    calcDischargingTime: {
      // 电池剩余时间可用时间
      type: String,
      default: "",
    },
    calcChargingTime: {
      type: String,
      default: "",
    },
    batteryStatus: {
      // 电池状态
      type: String,
      validator: (val: string) =>
        ["充电中", "已充满", "已断开电源"].includes(val),
    },
  },
});
</script>

<style lang="scss" scoped>
.container {
  position: absolute;
  bottom: 20vh;
  left: 50vw;
  width: 300px;
  height: 500px;
  transform: translateX(-50%);

  .number {
    position: absolute;
    top: 20%;
    z-index: 10;
    width: 300px;
    font-size: 32px;
    color: #fff;
    text-align: center;
  }

  .contrast {
    width: 300px;
    height: 400px;
    overflow: hidden;
    background: #000;
    filter: contrast(15) hue-rotate(0);
    animation: hueRotate 10s infinite linear;

    .circle {
      position: relative;
      width: 300px;
      height: 300px;
      filter: blur(8px);
      box-sizing: border-box;

      &::after {
        position: absolute;
        top: 40%;
        left: 50%;
        width: 200px;
        height: 200px;
        background-color: #00ff6f;
        border-radius: 42% 38% 62% 49% / 45%;
        content: "";
        transform: translate(-50%, -50%) rotate(0);
        animation: rotate 10s infinite linear;
      }

      &::before {
        position: absolute;
        top: 40%;
        left: 50%;
        z-index: 10;
        width: 176px;
        height: 176px;
        background-color: #000;
        border-radius: 50%;
        content: "";
        transform: translate(-50%, -50%);
      }
    }

    .bubbles {
      position: absolute;
      bottom: 0;
      left: 50%;
      width: 100px;
      height: 40px;
      background-color: #00ff6f;
      border-radius: 100px 100px 0 0;
      filter: blur(5px);
      transform: translate(-50%, 0);

      li {
        position: absolute;
        background: #00ff6f;
        border-radius: 50%;
      }
      // sass
       @for $i from 0 through 15 {
        li:nth-child(#{$i + 1}) {
          $width: 15 + random(15) + px;
          left: 15 + random(70) + px;
          top: 50%;
          transform: translate(-50%, -50%);
          width: $width;
          height: $width;
          animation: moveToTop #{random(6) + 3}s ease-in-out -#{calc(random(5000) / 1000)}s infinite;
        }
      }
      // @for $i from 0 through 15 {
      //   li:nth-child(#{$i}) {
      //     $width: 16 + random(15) + px;
      //     left: 54px + random(70) + px;
      //     top: 50%;
      //     transform: translate(-50%, -50%);
      //     width:  $width;
      //     height:  $width;
      //     animation: moveToTop 7s ease-in-out -0.427s infinite;
      //   }
      // }

      li:nth-child(0) {
        left: 54px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 16px;
        -webkit-animation: moveToTop 7s ease-in-out -0.427s infinite;
        animation: moveToTop 7s ease-in-out -0.427s infinite;
      }
      li:nth-child(1) {
        left: 38px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 26px;
        height: 26px;
        -webkit-animation: moveToTop 7s ease-in-out -3.191s infinite;
        animation: moveToTop 7s ease-in-out -3.191s infinite;
      }
      li:nth-child(2) {
        left: 57px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 29px;
        height: 29px;
        -webkit-animation: moveToTop 5s ease-in-out -0.663s infinite;
        animation: moveToTop 5s ease-in-out -0.663s infinite;
      }

      li:nth-child(3) {
        left: 63px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 23px;
        height: 23px;
        -webkit-animation: moveToTop 6s ease-in-out -4.723s infinite;
        animation: moveToTop 6s ease-in-out -4.723s infinite;
      }

      li:nth-child(4) {
        left: 75px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 16px;
        -webkit-animation: moveToTop 5s ease-in-out -0.649s infinite;
        animation: moveToTop 5s ease-in-out -0.649s infinite;
      }

      li:nth-child(5) {
        left: 64px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 19px;
        height: 19px;
        -webkit-animation: moveToTop 5s ease-in-out -1.091s infinite;
        animation: moveToTop 5s ease-in-out -1.091s infinite;
      }

      li:nth-child(6) {
        left: 78px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 23px;
        height: 23px;
        -webkit-animation: moveToTop 4s ease-in-out -0.379s infinite;
        animation: moveToTop 4s ease-in-out -0.379s infinite;
      }

      li:nth-child(7) {
        left: 17px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 28px;
        height: 28px;
        -webkit-animation: moveToTop 6s ease-in-out -1.476s infinite;
        animation: moveToTop 6s ease-in-out -1.476s infinite;
      }

      li:nth-child(8) {
        left: 58px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 16px;
        -webkit-animation: moveToTop 5s ease-in-out -2.649s infinite;
        animation: moveToTop 5s ease-in-out -2.649s infinite;
      }

      li:nth-child(9) {
        left: 47px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 25px;
        height: 25px;
        -webkit-animation: moveToTop 7s ease-in-out -2.013s infinite;
        animation: moveToTop 7s ease-in-out -2.013s infinite;
      }

      li:nth-child(10) {
        left: 18px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 28px;
        height: 28px;
        -webkit-animation: moveToTop 4s ease-in-out -0.648s infinite;
        animation: moveToTop 4s ease-in-out -0.648s infinite;
      }

      li:nth-child(11) {
        left: 23px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 25px;
        height: 25px;
        -webkit-animation: moveToTop 6s ease-in-out -0.115s infinite;
        animation: moveToTop 6s ease-in-out -0.115s infinite;
      }

      li:nth-child(12) {
        left: 27px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 19px;
        height: 19px;
        -webkit-animation: moveToTop 9s ease-in-out -2.652s infinite;
        animation: moveToTop 9s ease-in-out -2.652s infinite;
      }

      li:nth-child(13) {
        left: 48px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 29px;
        height: 29px;
        -webkit-animation: moveToTop 5s ease-in-out -0.82s infinite;
        animation: moveToTop 5s ease-in-out -0.82s infinite;
      }

      li:nth-child(14) {
        left: 17px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 29px;
        height: 29px;
        -webkit-animation: moveToTop 4s ease-in-out -1.454s infinite;
        animation: moveToTop 4s ease-in-out -1.454s infinite;
      }

      li:nth-child(15) {
        left: 25px;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 24px;
        height: 24px;
        -webkit-animation: moveToTop 5s ease-in-out -2.221s infinite;
        animation: moveToTop 5s ease-in-out -2.221s infinite;
      }
    }
  }

  .charging {
    font-size: 20px;
    text-align: center;
  }
}

@keyframes rotate {
  50% {
    border-radius: 45% / 42% 38% 58% 49%;
  }

  100% {
    transform: translate(-50%, -50%) rotate(720deg);
  }
}

@keyframes moveToTop {
  90% {
    opacity: 1;
  }

  100% {
    opacity: 0.1;
    transform: translate(-50%, -180px);
  }
}

@keyframes hueRotate {
  100% {
    filter: contrast(15) hue-rotate(360deg);
  }
}
</style>
